[][src]Crate wavy

Cross-platform real-time audio recording & playback.

The sound waves are so wavy!

Getting Started

This example records audio and plays it back in real time as it's being recorded. (Make sure to wear headphones to avoid feedback).

use wavy::*;

use std::collections::VecDeque;

fn main() -> Result<(), AudioError> {
    // Connect to the speaker and microphone systems.
    let mut mic = MicrophoneSystem::new(SampleRate::Normal)?;
    let mut speaker = SpeakerSystem::new(SampleRate::Normal)?;

    let mut buffer = VecDeque::new();

    loop {
        // Record some sound.
        mic.record(&mut |_whichmic, l, r| {
            buffer.push_back((l, r));
        });

        // Play that sound.
        speaker.play(&mut || {
            if let Some((lsample, rsample)) = buffer.pop_front() {
                AudioSample::stereo(lsample, rsample)
            } else {
                // Play silence if not enough has been recorded yet.
                AudioSample::stereo(0, 0)
            }
        });
    }
}

Structs

AudioSample

An AudioSample (with surround sound 5.1 support).

MicrophoneSystem

Audio (Microphone) input.

SpeakerSystem

Audio (Speaker) output. This type represents a speaker system.

Enums

AudioError

Error for opening audio device for reading (recording) or writing (playing).

SampleRate

3 sample rates which are supported by this crate.